#ifndef LOGINDIALOG_H
#define LOGINDIALOG_H

#include <QDialog>
#include <QMap>
#include "global.h"
namespace Ui {
class LoginDialog;
}

class LoginDialog : public QDialog
{
    Q_OBJECT

public:
    explicit LoginDialog(QWidget *parent = nullptr);
    ~LoginDialog();

signals:
    void sigSwitchRegister();
    void sigSwitchForget();
    void sig_connect_tcp(ServerInfo si);
    void sig_switch_chatdlg();
private slots:
    void on_btn_signup_clicked();
    void on_btn_froget_clicked();
    void on_btn_login_clicked();
    void slot_login_finished(ReqId id, QString res, ErrorCode ec);
    void slot_login_failed(int);
    void slot_tcp_con_finish(bool success);

private:
    Ui::LoginDialog *ui;
    QMap<ReqId, std::function<void(QJsonObject &)>> _handles;
    int _uid;
    QString _token;

private:
    void initHead();
    bool CheckEmailValid();
    bool CheckPassWordValid();
    void setBtnEnabled(bool enabled);
    void initHttpHandlers();
};

#endif // LOGINDIALOG_H
